#include <iostream>
#include <algorithm>
#include <iterator>
using namespace std;

void Range(char str[], int len, int pos) {
	if (pos == len-1) {
		std::copy(str, str+len, ostream_iterator<char>(cout, " "));
		cout << endl;
	}
	for (int i = pos ; i < len; i++) {
		std::swap(str[pos], str[i]);
		Range(str, len, pos+1);
		std::swap(str[pos], str[i]);
	}

}

int main() {
	char str[] = "123";
	Range(str, 3, 0);
	return 0;
}
